home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c++ / 912 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  1.9 KB

  1. From: brianmcg@interaccess.com (Brian V. McGroarty)
  2. Message-ID: <4jgpqa$t09@nntp.interaccess.com>
  3. X-Original-Date: 29 Mar 1996 13:50:02 GMT
  4. Path: in2.uu.net!bounce-back
  5. Date: 30 Mar 96 05:46:49 GMT
  6. Approved: fjh@cs.mu.oz.au
  7. Return-Path: <daemon@meeker.UCAR.EDU>
  8. Newsgroups: comp.std.c++
  9. Subject: Const class member
  10. Organization: Internet Squire
  11. Reply-To: brianmcg@interaccess.com
  12. X-Newsreader: Internet Squire 1.20
  13. X-Auth: PGPMoose V1.1 PGP comp.std.c++
  14.     iQBFAgUBMVzK1OEDnX0m9pzZAQGYgwF/dbBcO6j67CzzpYGFvO3mKbaRFB+D0wg1
  15.     BlqNx35Ycjs3vClZ3siiQlHsC97HHNHe
  16.     =pace
  17.  
  18. Is this legal?  Borland and Microsoft compilers will accept the following:
  19.  
  20. class AnyClass
  21. {
  22.     const int constInt;
  23. }
  24.  
  25. The Borland compiler complains about the uninitialized constant, whereas
  26. the Microsoft compiler does not.  If a constructor is present, both will
  27. complain that the constant isn't initialized in the constructor, however
  28. neither will allow you to assign a value in the constructor by simply
  29. specifying "constInt= some value".  I have also attempted to initialize in
  30. a global variable "int AnyClass::constInt",  to determine whether static
  31. somehow became implicit -- still no go.  If this is legal, how is the value
  32. initialized?
  33.  
  34. Would compilers stand a better chance of optimizing given the above via
  35. constant propogation through inlined (member only?) functions applied to a
  36. hard-coded instance of the object, or would it just be to help prevent
  37. programmers' error?
  38.  
  39. ---
  40. Brian Valters McGroarty -- brianmcg@bix.com
  41. phone/fax (847) 439-7714
  42. ---
  43. [ comp.std.c++ is moderated.  To submit articles: try just posting with      ]
  44. [ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu         ]
  45. [ FAQ:      http://reality.sgi.com/employees/austern_mti/std-c++/faq.html    ]
  46. [ Policy:   http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
  47. [ Comments? mailto:std-c++-request@ncar.ucar.edu                             ]
  48.